package com.sz.jinzheng.service.impl;

import com.sz.jinzheng.mapper.TbillFormMapper;
import com.sz.jinzheng.model.BillForm;
import com.sz.jinzheng.model.Interest;
import com.sz.jinzheng.service.TbillFormService;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@MapperScan("com.sz.jinzhen.mapper")
public class TbillFormSericeImp implements TbillFormService {
    @Autowired
    private TbillFormMapper tbillFormMapper;//从SPring容器中取出mapper方法

    @Override
    public BillForm getAllRepayment(Integer id) {
        return tbillFormMapper.getAllRepayment(id);//通过id查询
    }

    //    public  BillForm getInterest(Integer id) {//通过ID查询用户选择的还款方式
//        return tbillFormMapper.getInterest(id);
//    }
    public Interest getInterest(Integer id) {
        return tbillFormMapper.getInterest(id);
    }

    public BillForm overtime(Integer id) {//查询是否逾期和逾期后的违约率;
        return tbillFormMapper.overtime(id);
    }


    @Override
    public int insertbill(Integer userId, Integer billFormId, Integer borrowInfoId, Integer whichIssue, Double capital, Double principalAndInterest, Double interest, Integer status, Integer overdueDays, Double penaltyRate, Double penaltyInterest, Date startTime, Date endTime, Date createTime, Date updateTime, Integer isDeleted) {
        return tbillFormMapper.insertbill(userId, billFormId, borrowInfoId, whichIssue, capital, principalAndInterest, interest, status, overdueDays, penaltyRate, penaltyInterest, startTime, endTime, createTime, updateTime, isDeleted);
    }

    @Override
    public List<BillForm> getArrears(Integer borrowInfoId) {
        return tbillFormMapper.getArrears(borrowInfoId);
    }

    @Override
    public List<BillForm> getArrears1(Integer borrowInfoId) {
        return tbillFormMapper.getArrears1(borrowInfoId);
    }

    @Override
    public int updateForm(BillForm billForm) {//修改账单
        return tbillFormMapper.updateForm(billForm);
    }

    @Override
    public int updateFormOverdue(Integer id, Integer status, Integer overdueDays, Double penaltyInterest) {//修改账单状态为逾期
        return tbillFormMapper.updateFormOverdue(id, status, overdueDays, penaltyInterest);
    }

    @Override
    public BillForm timePayment(Integer whichIssue, Integer borrowInfoId, Integer id) {//查询账单通过当前第几期和用户id
        return tbillFormMapper.timePayment(whichIssue, borrowInfoId, id);
    }

    @Override
    public BillForm getzhangdan(Integer id, Integer whichIssue) {
        return tbillFormMapper.getzhangdan(id, whichIssue);


    }

    /**
     * 用户提前还款成功修改账单！
     *
     * @param borrowInfoId 账单id
     * @return
     */
    public int payPrepayment(Integer borrowInfoId) {
        return tbillFormMapper.payPrepayment(borrowInfoId);
    }

    ;
}
